import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:share_fit/app/models/base_model.dart';

class SportGpsData extends BaseModel {
  /// 开始时间，格式：yyyyMMddHHmmss
  final String? startTime;

  /// GCJ02 经度值，小数点后精度保留 7
  final double? gcj02Longitude;

  /// GCJ02 纬度值，小数点后精度保留 7 位
  final double? gcj02Latitude;

  /// WGS84 纬度值，小数点后精度保留 7 位
  final double? gpsLatitude;

  /// WGS84 经度值，小数点后精度保留 7 位
  final double? gpsLongitude;

  /// 海拔高度，取值范围[-32768,32767]。单位：米
  final int? altitude;

  /// 位置精度（置信度为 68%），单位：米
  final double? accuracy;

  /// 方向，取值范围[0.0,360.0]，单位:度
  final double? bearing;

  /// 速度，单位：分米/秒
  final int? speed;

  SportGpsData({
    this.bearing = 0,
    this.speed = 0,
    this.startTime,
    this.gcj02Longitude = 0.0,
    this.gcj02Latitude = 0.0,
    this.gpsLatitude = 0.0,
    this.gpsLongitude = 0.0,
    this.altitude = 0,
    this.accuracy = 0,
  });

  @override
  bool from(Map map) {
    return true;
  }

  @override
  toMap() {
    // TODO: implement toMap
    return super.toMap();
  }

  Map toJson() => {
    'bearing': bearing,
    'speed': speed,
    'startTime': startTime,
    'gcj02Longitude': gcj02Longitude,
    'gcj02Latitude': gcj02Latitude,
    'gpsLatitude': gpsLatitude,
    'gpsLongitude': gpsLongitude,
    'altitude': altitude,
    'accuracy': accuracy,
  };

  @override
  List<Object?> get props => [
        bearing,
        speed,
        startTime,
        gcj02Longitude,
        gcj02Latitude,
        gpsLatitude,
        gpsLongitude,
        altitude,
        accuracy,
      ];

  @override
  bool? get stringify => true;

  LatLng toLatLng() {
    return LatLng(gpsLatitude!, gpsLongitude!);
  }

  bool exists(LatLng latLng) {
    return gpsLatitude == latLng.latitude && gpsLongitude == latLng.longitude;
  }
}
